package com.util;

import io.swagger.annotations.ApiModelProperty;

import java.io.Serializable;

/**
 * @ClassName Result
 * @Description 返回结果实体类
 * @Author by nike
 * @Date 2020/7/8 22:41
 * @Version V1.0
 **/
public class Result<T> implements Serializable {

    @ApiModelProperty(value = "是否成功")
    private boolean flag;//是否成功

    @ApiModelProperty(value = "返回码")
    private Integer code;//返回码

    @ApiModelProperty(value = "返回消息")
    private String message;//返回消息

    @ApiModelProperty(value = "返回数据")
    private T data;//返回数据


    public static <T> Result<T> buildSuccess(String message,T data){
        return new Result<T>(true,StatusCode.OK,message,data);
    }

    public static <T> Result<T> buildSuccess(String message){
        return new Result<T>(true,StatusCode.OK,message);
    }

    public static <T> Result<T> buildFail(String message){
        return new Result<T>(false,StatusCode.ERROR,message);
    }

    public Result(boolean flag, Integer code, String message, T data) {
        this.flag = flag;
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public Result(boolean flag, Integer code, String message) {
        this.flag = flag;
        this.code = code;
        this.message = message;
    }

    public Result() {
        this.flag = true;
        this.code = StatusCode.OK;
        this.message = "操作成功!";
    }

    public boolean isFlag() {
        return flag;
    }

    public void setFlag(boolean flag) {
        this.flag = flag;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
